package com.piece.admin.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.piece.core.framework.annotation.translate.DicTranslate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@NoArgsConstructor
@Table(name = "tb_sys_job")
@ApiModel(value = "定时任务调度表")
public class TbSysJob implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "job_id", length = 11)
    @ApiModelProperty(value = "任务ID")
    private Long jobId;

    @Column(name = "job_name")
    @ApiModelProperty(value = "任务名称")
    private String jobName;

    @Column(name = "job_group")
    @ApiModelProperty(value = "任务组名")
    private String jobGroup;

    @Column(name = "method_name")
    @ApiModelProperty(value = "任务方法")
    private String methodName;

    @Column(name = "method_param")
    @ApiModelProperty(value = "方法参数", notes = "参数只能是ScheduleJob类或为空")
    private String methodParam;

    @Column(name = "cron_expression")
    @ApiModelProperty(value = "cron执行表达式")
    private String cronExpression;

    @Column(name = "misfire_policy")
    @ApiModelProperty(value = "cron计划策略")
    private String misfirePolicy;

    @Column(name = "concurrent")
    @ApiModelProperty(value = "是否并发执行", notes = "0允许, 1禁止")
    private String concurrent;

    @Column(name = "status")
    @ApiModelProperty(value = "任务状态", notes = "0完成, 1删除, 2执行中, 3暂停, 4错误")
    private String status;

    @Column(name = "retry_count")
    @ApiModelProperty(value = "重试次数", notes = "0表示不重试")
    private Integer retryCount;

    @Column(name = "retry_interval")
    @ApiModelProperty(value = "重试间隔(毫秒)")
    private Integer retryInterval;

    @Column(name = "create_by", length = 11)
    @DicTranslate(target = "createByName", proxy = "tbSysUserService.convertIdToName")
    @ApiModelProperty(value = "创建人")
    private String createBy;

    @Transient
    @ApiModelProperty(value = "创建人名称")
    private String createByName;

    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createTime;
}
